//连接数据库
const express = require('express');
const mysql = require('mysql');

// 创建MySQL连接池
const pool = mysql.createPool({
    connectionLimit: 10,
    host: 'localhost',
    user: 'root',
    password: '1234',
    database: 'springboot_demo'
});

const app = express();
const port = 3000;

// 用于解析JSON类型的请求体
app.use(express.json());

// API端点，返回数据库中的数据
app.get('/api/items', (req, res) => {
    pool.query('SELECT * FROM dept', (error, results) => {
        if (error) {
            return res.status(500).json({ error: error.message });
        }
        res.json(results);
    });
});
app.listen(port, () => {
    console.log(`Server running on port ${port}`);
});